<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
$conn = @mysql_connect("localhost","root","root");
if (!$conn){
    die("Could not connect：" . mysql_error());
}

mysql_select_db("hero", $conn);
mysql_query("set names 'UTF-8'"); 
 
$deviceid_query =  mysql_query("SELECT DISTINCT deviceid,registerDate FROM hero where  registerDate between '2012-06-01' and '2012-06-30'");

while($deviceid = mysql_fetch_array($deviceid_query))
{
     //进入游戏次数
    $playNum_query = mysql_query("SELECT count(1) FROM hero where deviceid = '$deviceid[deviceid]'");

    $playNum = mysql_fetch_array($playNum_query);

     //总游戏时间
    $TotalGameTime_query = mysql_query("SELECT allGameTime FROM hero_last where deviceid = '$deviceid[deviceid]'");
    $TotalGameTime = mysql_fetch_array($TotalGameTime_query);

    //最后停留等级
    $level_query = mysql_query("SELECT heroData_0_level FROM hero_last where deviceid = '$deviceid[deviceid]'");
    $level = mysql_fetch_array($level_query);

    //成活率 Survival
    $Survival_query = mysql_query("SELECT  count(1) FROM hero WHERE  date > DATE_ADD( '$deviceid[registerDate]', INTERVAL 7 DAY ) and  deviceid = '$deviceid[deviceid]'");
    $Survival = mysql_fetch_array($Survival_query);
         //cents099 购买次数
    $_099cents1_query = mysql_query("SELECT sum(cents099) FROM hero where deviceid = '$deviceid[deviceid]'");
    $_099cents1 = mysql_fetch_array($_099cents1_query);
        //Cents1999 购买次数
    $_099cents2_query = mysql_query("SELECT sum(Cents1999) FROM hero where deviceid = '$deviceid[deviceid]' ");
    $_099cents2 = mysql_fetch_array($_099cents2_query);
        //Cents499 购买次数
    $_new499cents1_query = mysql_query("SELECT sum(Cents499) FROM hero where deviceid = '$deviceid[deviceid]' ");
    $_new499cents1 = mysql_fetch_array($_new499cents1_query);
        //Cents4999 购买次数
    $_new499cents2_query = mysql_query("SELECT sum(Cents4999) FROM hero where deviceid = '$deviceid[deviceid]' ");
    $_new499cents2 = mysql_fetch_array($_new499cents2_query);
        //Cents9999 购买次数
    $_new999cents1_query = mysql_query("SELECT sum(Cents9999) FROM hero where deviceid = '$deviceid[deviceid]' ");
    $_new999cents1 = mysql_fetch_array($_new999cents1_query);

        //最后停留等级
    $level1_query = mysql_query("SELECT heroData_1_level FROM hero_last where deviceid = '$deviceid[deviceid]'");
    $level1 = mysql_fetch_array($level1_query);

        //最后停留等级
    $level2_query = mysql_query("SELECT heroData_2_level FROM hero_last where deviceid = '$deviceid[deviceid]'");
    $level2 = mysql_fetch_array($level2_query);

        //最后停留等级
    $level3_query = mysql_query("SELECT heroData_3_level FROM hero_last where deviceid = '$deviceid[deviceid]'");
    $level3 = mysql_fetch_array($level3_query);
   
 
$sql = "UPDATE report_nojailbreak_total SET playNum= '$playNum[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql2 = "UPDATE report_nojailbreak_total SET TotalGameTime= '$TotalGameTime[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql3 = "UPDATE report_nojailbreak_total SET Survival= '$Survival[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql4 = "UPDATE report_nojailbreak_total SET level= '$level[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql5 = "UPDATE report_nojailbreak_total SET cents099= '$_099cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql6 = "UPDATE report_nojailbreak_total SET Cents1999= '$_099cents2[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql7 = "UPDATE report_nojailbreak_total SET Cents499= '$_new499cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql8 = "UPDATE report_nojailbreak_total SET Cents4999= '$_new499cents2[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql9 = "UPDATE report_nojailbreak_total SET Cents9999= '$_new999cents1[0]' WHERE deviceid= '$deviceid[deviceid]'";

$sql10 = "UPDATE report_nojailbreak_total SET level1= '$level1[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql11 = "UPDATE report_nojailbreak_total SET level2= '$level2[0]' WHERE deviceid= '$deviceid[deviceid]'";
$sql12 = "UPDATE report_nojailbreak_total SET level3= '$level3[0]' WHERE deviceid= '$deviceid[deviceid]'";


if(mysql_query($sql,$conn)){
    echo "1 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql2,$conn)){
    echo "2 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql3,$conn)){
    echo "3 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql4,$conn)){
    echo "4 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql5,$conn)){
    echo "5 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql6,$conn)){
    echo "6 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql7,$conn)){
    echo "7 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql8,$conn)){
    echo "8 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql9,$conn)){
    echo "9 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql10,$conn)){
    echo "10 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql11,$conn)){
    echo "11 update is ok!";
} else {
    echo "failed：".mysql_error();
}
if(mysql_query($sql12,$conn)){
    echo "12 update is ok!";
} else {
    echo "failed：".mysql_error();
}


}
?>
